package com.yunkeji.admin.controller.sys;

import java.util.Arrays;

import com.yunkeji.dao.vo.sys.SysIpDeviceBannedVo;
import com.yunkeji.system.domain.bo.SysIpDeviceBannedBo;
import com.yunkeji.system.service.SysIpDeviceBannedService;
import lombok.RequiredArgsConstructor;
import javax.validation.Valid;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.yunkeji.common.annotation.RepeatSubmit;
import com.yunkeji.common.annotation.Log;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.PageQuery;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.common.core.validate.EditGroup;
import com.yunkeji.common.enums.BusinessType;
import com.yunkeji.common.core.page.TableDataInfo;

/**
 * 封禁IP和设备记录
 *
 * @author yunkeji
 * @date 2024-09-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/sysIpDeviceBanned")
public class SysIpDeviceBannedController extends BaseController {

    private final SysIpDeviceBannedService sysIpDeviceBannedService;

    /**
     * 查询封禁IP和设备记录列表
     */
    @SaCheckPermission("system:sysIpDeviceBanned:list")
    @GetMapping("/list")
    public TableDataInfo<SysIpDeviceBannedVo> list(SysIpDeviceBannedBo bo, PageQuery pageQuery) {

        return sysIpDeviceBannedService.queryPageList(bo, pageQuery);
    }
    /**
     * 获取封禁IP和设备记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:sysIpDeviceBanned:query")
    @GetMapping("/{id}")
    public R<SysIpDeviceBannedVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(sysIpDeviceBannedService.queryById(id));
    }

    /**
     * 新增封禁IP和设备记录
     */
    @SaCheckPermission("system:sysIpDeviceBanned:add")
    @Log(title = "封禁IP和设备记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Valid @RequestBody SysIpDeviceBannedBo bo) {
        sysIpDeviceBannedService.insertByBo(bo);
        return R.ok();
    }

    /**
     * 修改封禁IP和设备记录
     */
    @SaCheckPermission("system:sysIpDeviceBanned:edit")
    @Log(title = "封禁IP和设备记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysIpDeviceBannedBo bo) {
        return toAjax(sysIpDeviceBannedService.updateByBo(bo));
    }

    /**
     * 删除封禁IP和设备记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:sysIpDeviceBanned:remove")
    @Log(title = "封禁IP和设备记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(sysIpDeviceBannedService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
